package com.abc.app.tests;

import static org.testng.Assert.assertEquals;

import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.abc.app.pages.HomePage;
import com.abc.app.pages.LoginPage;


public class LoginTest extends BaseTest{

	private RemoteWebDriver driver;
	
	@Parameters({ "browser", "os" })
	public LoginTest(String browser, String os) {
		super(browser, os);
		System.out.println("LoginTest");
	}
	
	public LoginTest() {
		super();
	}

	@BeforeGroups("group")
	public void setUp(){
		System.out.println("@BeforeClass");
		System.out.println(browser + ":"+ os);
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setBrowserName(browser);
		capabilities.setPlatform(Platform.valueOf(os));
		
		driver = getRemoteWebDriver("http://localhost:4444/wd/hub", capabilities);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}
	
	@Test(groups = "group")
	public void verifyHomePageTitle(){
		System.out.println("verifyHomePageTitle");
		driver.get("https://login.comcast.net/login?ts=f52455ef&s=wnamp");
		
		waitt(1000);
		
		LoginPage loginPage = new LoginPage(driver);
		loginPage.setUsername("joseph.betty@comcast.net");
		loginPage.setPassword("comcast12345");
		HomePage homePage = loginPage.clickLoginButton();
		
		String pageTitle = homePage.getPageTitle();
		System.out.println(pageTitle);
		
		boolean loginSucess = StringUtils.contains(pageTitle, "XFINITY Connect: Inbox");
		
		waitt(2000);
		
		assertEquals(loginSucess, true);
		
		driver.close();
	}
}
